/* * Octobrite Test * 7/1/2009 - yergacheffe@atomsandelectrons.com * * Cycles through a series of colors by linear interpolation * which gives a nice fading effect. There are multiple * interpolation modes which affect how the colors progress * through the 8 LEDs. */ // Color channel constants #define RED 0 #define GREEN 1 #define BLUE 2 // TLC5947 maintains 12 bits of grayscale per LED channel #define CHANNEL_BITS 12 #define CHANNEL_MAX (long)( (1<=0; --bit) { if (value & (1<0; --index) { colorHistory[index][0] = colorHistory[index-1][0]; colorHistory[index][1] = colorHistory[index-1][1]; colorHistory[index][2] = colorHistory[index-1][2]; } colorHistory[0][0] = red; colorHistory[0][1] = green; colorHistory[0][2] = blue; } // Disbaled debug output if (false) { Serial.print("RGB=("); Serial.print(red); Serial.print(", "); Serial.print(green); Serial.print(", "); Serial.print(blue); Serial.println(")"); } if (interpolationMode == INTERPOLATION_MODE_SHIFT) { // Now write the next RGB value, which will shift the colors // down along the other LEDs WriteChannel(blue); WriteChannel(green); WriteChannel(red); } else if (interpolationMode == INTERPOLATION_MODE_CENTEROUT) { // For this one we need to update all 8 LEDs for (index=3; index>=0; --index) { WriteChannel(colorHistory[index][0]); WriteChannel(colorHistory[index][1]); WriteChannel(colorHistory[index][2]); } for (index=0; index<=3; ++index) { WriteChannel(colorHistory[index][0]); WriteChannel(colorHistory[index][1]); WriteChannel(colorHistory[index][2]); } } else if (interpolationMode == INTERPOLATION_MODE_COMB) { for (index=0; index<=3; ++index) { WriteChannel(colorHistory[0][0]); WriteChannel(colorHistory[0][1]); WriteChannel(colorHistory[0][2]); WriteChannel(CHANNEL_MAX*previousColor[RED]/100); WriteChannel(CHANNEL_MAX*previousColor[GREEN]/100); WriteChannel(CHANNEL_MAX*previousColor[BLUE]/100); } } // Finally latch in the new color values digitalWrite(XLAT_PIN, HIGH); delay(1); digitalWrite(XLAT_PIN, LOW); } void loop() { // Step the interpolation by one frame ++lerpindex; if (lerpindex > lerpsteps) { // We finished the interpolation between the current // color pair. Set up the next color pair. NextColor(); } // Update the LEDs WriteColors(); // Throttle the animation delay(stepdelay); }